﻿package com.tomvian.twodee.sideon.actions
{
	import flash.display.MovieClip;
	import com.tomvian.twodee.common.actions.Action;
	import com.tomvian.twodee.common.Actor;
	import com.tomvian.twodee.common.interactions.Interaction;
	import com.tomvian.maths.Vector2D;
	
	/**
	 * Pushing
	 * @author Thomas Vian
	 */
	public class Pushing extends Action
	{
		//--------------------------------------------------------------------------
		//
		//  Properties
		//
		//--------------------------------------------------------------------------
		
		public static const DISPLAY_PUSHING:String = "pushing";
		
		public var blocks:Interaction;
		
		public var accel:Number;
		
		//--------------------------------------------------------------------------
		//	
		// Getters / Setters
		//
		//--------------------------------------------------------------------------
		
		//--------------------------------------------------------------------------
		//	
		//  Constructor
		//
		//--------------------------------------------------------------------------
		
		public function Pushing(actor:Actor, blocks:Interaction, accel:Number)
		{
			super(actor);
			
			this.blocks = blocks;
			this.accel = accel;
		}
		
		//--------------------------------------------------------------------------
		//	
		//  Methods
		//
		//--------------------------------------------------------------------------
		
		override public function stop():void 
		{
			actorMass.velocity.x = 0;
		}
		
		override public function act():void 
		{
			if (enabled)
			{
				if (blocks.interacting)
				{
					if (actor.direction == 1)
					{
						if (actorController.right) 		
						{
							actorMass.velocity.x += accel;
						}
						else if (actorController.left)	
						{
							actor.returnToDefault();
						}
						else
						{
							actorMass.velocity.x = 0;
						}
					}
					else if (actor.direction == 3)
					{
						if (actorController.left) 		
						{
							actorMass.velocity.x -= accel;
						}
						else if (actorController.right)	
						{
							actor.returnToDefault();
						}
						else
						{
							actorMass.velocity.x = 0;
						}
					}
				}
				else if (blocks.wasInteracting)
				{
					actor.returnToDefault();
				}
			}
		}
		
		override public function display():void 
		{
			actorState.state = DISPLAY_PUSHING;
		}
	}
}